<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>

<div class="page-container">
<h2 class="text-c" style="padding: 0;">费用分摊</h2>
    <div style="padding-top:20px;">
	
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                <thead>
                <tr class="text-c" role="row">
					<th width="40">ID</th>
					<th width="40">采购单编号</th>
					<th width="40">商品编码</th>
					<th width="40">商品名称</th>
					<th width="40">销售单价</th>
					<th width="40">分摊金额</th>
					<th width="40">数量</th>
					<th width="40">规格</th>
					<th width="40">原产国</th>

                </tr>
                </thead>
                <tbody>
                <foreach name="list" item="data">
                    <tr class="text-c odd" role="row">
						<td><{$data.id}></td>
						<td><span><{$detail.order_no}></span></td>
						<td><{$data.goods_sn}></td>
						<td><{$data.goods_name}></td>
						<td>
							<{$data['goods_price']}>
						</td>
						<td>
							<{$data['share_fee']}>
						</td>
						<td>
							<{$data.goods_nums}>
						</td>
						<td>
							<{$data.spec}>
						</td>
						<td>
							 <select name="country_code" class="form-control selects" 
								 <volist name="country" id="vcc">
									<if condition="$vcc['country_code'] == $data['source']">disabled="disabled"  style="width:130px;background:#ccc;"
									</if>
								 </volist>
							 >
								 <option value="">请选择</option>
								 <volist name="country" id="vcc">
									 <option value="<{$vcc.country_code}>" <if condition="$vcc['country_code'] == $data['source']">selected</if>><{$vcc.country_name}></option>
								 </volist>
							 </select>
						</td>
				
                    </tr>
                </foreach>
                </tbody>
            </table>
			<div style="margin-top: 12px;">
				<a href="javascript:;" onclick="add()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>添加费用名称</a>
				<table class="table table-border table-bordered table-bg">
					<thead>
						<tr>
							<th scope="col" colspan="15">费用名称列表</th>
						</tr>
						<tr class="text-c">
							<!-- <th><input type="checkbox" name=""></th> -->
							<th>序号</th>
							<th width="">费用名称编号</th>
							<th width="">费用名称名称</th>
							<th width="">金额</th>
							
						</tr>
					</thead>
					<tbody>
						<volist name="list_cost" id="vo">
						<tr class="text-c">
							<!-- <td><input type="checkbox" class="ids" name="ids" value="<{$vo.id}>" name=""></td> -->
							<td><{$i}></td>
							<td><{$vo.no}></td>
							<td><{$vo.name}></td>
							<td><input class="input-text" attr_id="<{$vo.id}>" style="width:50px" type="text" value="<{$vo.total_fee}>" name="total_fee"></td>
						</tr>
						</volist>			
					</tbody>
				</table>
				<a href="javascript:;" onclick="confirm_edit()" class="btn btn-success radius"><i class="Hui-iconfont"></i>修改</a>
				<a href="javascript:;" onclick="share_num()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>按数量分摊</a>
				<a href="javascript:;" onclick="share_fee()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>按金额分摊</a>
            </div>
        </div>
    </div>
    <include file="Public/footer_js" />
    <script>
		function add(){
			id=<{$Think.get.id}>;
			var index=layer.open({
				type: 2,
				title: '费用名称列表',
				shadeClose: true,
				shade: 0.5,
				area: ['1000px', '500px'],
				content: '__MODULE__/Salesman/cost/id/'+id+'/'+Math.random() //iframe的url
			});
		}
		function confirm_edit(){
			var option = $('input[name=total_fee]');
			var ids= [];
			var prices= [];
            for(i=0;i<option.length;i++){
				ids.push(option.eq(i).attr('attr_id'));
				prices.push(option.eq(i).val());
			}
			//订单检查，是否已生成波次单
			$.ajax({
				type: 'POST',
				data: {ids:ids,prices:prices},
				url: "<{:U('cost_edit')}>",
				success:function(data){
					if(data.status==1){	//检查通过，跳转生成波次单页面
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{				//检查未通过，刷新页面
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
		function share_num(){
			id=<{$Think.get.id}>;
			$.ajax({
				type: 'POST',
				data: {id:id},
				url: "<{:U('share_num')}>",
				success:function(data){
					if(data.status==1){
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
		function share_fee(){
			id=<{$Think.get.id}>;
			$.ajax({
				type: 'POST',
				data: {id:id},
				url: "<{:U('share_fee')}>",
				success:function(data){
					if(data.status==1){
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
    </script>
</body>
</html>